package org.example.myleet.p537;

public class Solution {
    public String complexNumberMultiply(String num1, String num2) {
        String[] elements = num1.split("\\+|i");
        int a1 = Integer.parseInt(elements[0]);
        int b1 = Integer.parseInt(elements[1]);
        elements = num2.split("\\+|i");
        int a2 = Integer.parseInt(elements[0]);
        int b2 = Integer.parseInt(elements[1]);
        int a = a1 * a2 - (b1 * b2);
        int b = a1 * b2 + a2 * b1;
        StringBuilder sb = new StringBuilder();
        sb.append(a).append('+').append(b).append('i');
        return sb.toString();
    }
}
